<?php 
include_once $_SERVER['DOCUMENT_ROOT'].'/Par-Ideal/PROJETO/src/util/Conexao.php';

class VerificaEmailCPFDao{

	public function verifica($email, $cpf){
		$conexao = Conexao::Conecta();
		 $retorno;
		$sql = "SELECT COUNT(login) as cont FROM usuario WHERE login = '".$email."'";
		if (!($stmt = $conexao->prepare($sql))) {
  			echo "Falha no stmt (Formata.formataDao): (" . $conexao->errorCode . ") ";  			
  			 print_r($stmt->errorInfo());
		}	
			
		if (!$stmt->execute()) {
   			 echo "Erro ao executar(Formata.formataDao): (" . $conexao->errorCode() . ") ";
   			  print_r($stmt->errorInfo());
		}
		
			while ($linha = $stmt->fetchObject()) {
				$retorno = $linha->cont;
	 	   }
	 	
	 	if($retorno > 0){
	 		header("Location: erro.php");
	 	}
	 	
		$sql = "SELECT COUNT(cpf) as cont FROM cliente WHERE CPF = ".$cpf;
		if (!($stmt = $conexao->prepare($sql))) {
  			echo "Falha no stmt (Formata.formataDao): (" . $conexao->errorCode . ") ";  			
  			 print_r($stmt->errorInfo());
		}	
			
		if (!$stmt->execute()) {
   			 echo "Erro ao executar(Formata.formataDao): (" . $conexao->errorCode() . ") ";
   			  print_r($stmt->errorInfo());
		}
		
			while ($linha = $stmt->fetchObject()) {
				$retorno = $linha->cont;
	 	   }
	 	
	 	if($retorno > 0){
	 		header("Location: erro.php");
	 	}
	 	
		$sql = "SELECT COUNT(cpf) as cont FROM funcionario WHERE CPF = ".$cpf;
		if (!($stmt = $conexao->prepare($sql))) {
  			echo "Falha no stmt (Formata.formataDao): (" . $conexao->errorCode . ") ";  			
  			 print_r($stmt->errorInfo());
		}	
			
		if (!$stmt->execute()) {
   			 echo "Erro ao executar(Formata.formataDao): (" . $conexao->errorCode() . ") ";
   			  print_r($stmt->errorInfo());
		}
		
			while ($linha = $stmt->fetchObject()) {
				$retorno = $linha->cont;
	 	   }
	 	
	 	if($retorno > 0){
	 		header("Location: erro.php");
	 	}
	 	return $retorno;
		
	}
	
	
	public function verificaAlterarInformacoes($email, $cpf, $idCliente){
				$conexao = Conexao::Conecta();
		 $retorno;
		$sql = "SELECT COUNT(login) as cont FROM usuario WHERE login = '".$email."' and id_usuario!=".$idCliente;
		if (!($stmt = $conexao->prepare($sql))) {
  			echo "Falha no stmt (Formata.formataDao): (" . $conexao->errorCode . ") ";  			
  			 print_r($stmt->errorInfo());
		}	
			
		if (!$stmt->execute()) {
   			 echo "Erro ao executar(Formata.formataDao): (" . $conexao->errorCode() . ") ";
   			  print_r($stmt->errorInfo());
		}
		
			while ($linha = $stmt->fetchObject()) {
				$retorno = $linha->cont;
	 	   }
	 	
	 	if($retorno > 0){
	 		header("Location: /Par-Ideal/PROJETO/views/erro.php");
	 	}
	 	
		$sql = "SELECT COUNT(cpf) as cont FROM cliente WHERE CPF = ".$cpf." and id_cliente !=".$idCliente;
		if (!($stmt = $conexao->prepare($sql))) {
  			echo "Falha no stmt (Formata.formataDao): (" . $conexao->errorCode . ") ";  			
  			 print_r($stmt->errorInfo());
		}	
			
		if (!$stmt->execute()) {
   			 echo "Erro ao executar(Formata.formataDao): (" . $conexao->errorCode() . ") ";
   			  print_r($stmt->errorInfo());
		}
		
			while ($linha = $stmt->fetchObject()) {
				$retorno = $linha->cont;
	 	   }
	 	
	 	if($retorno > 0){
	 		header("Location: /Par-Ideal/PROJETO/views/erro.php");
	 	}
	 	
		$sql = "SELECT COUNT(cpf) as cont FROM funcionario WHERE CPF = ".$cpf;
		if (!($stmt = $conexao->prepare($sql))) {
  			echo "Falha no stmt (Formata.formataDao): (" . $conexao->errorCode . ") ";  			
  			 print_r($stmt->errorInfo());
		}	
			
		if (!$stmt->execute()) {
   			 echo "Erro ao executar(Formata.formataDao): (" . $conexao->errorCode() . ") ";
   			  print_r($stmt->errorInfo());
		}
		
			while ($linha = $stmt->fetchObject()) {
				$retorno = $linha->cont;
	 	   }
	 	
	 	if($retorno > 0){
	 		header("Location: /Par-Ideal/PROJETO/views/erro.php");
	 	}
	 	return $retorno;
		
		
	}
}

?>